<?php

	class photosModel {

		/**
		 * FormContact::__construct()
		 *
		 */
		public function __construct ( ) {
		}

		public function showAllPhotos($directory){
			# Lecture du dossier de la gallerie
			$allowed_types=array('jpg','jpeg','gif','png');
			$file_parts=array();
			$ext='';
			$title='';
			$i=0;


			/* PHOTOS */
			$dir_handle = @opendir($directory) or die("Il y a une erreur avec le dossier d'image");

			$key = 0;

			while ($file = readdir($dir_handle))
			{
				if($file=='.' || $file == '..') continue;

				$file_parts = explode('.',$file);
				$ext = strtolower(array_pop($file_parts));

				$title = implode('.',$file_parts);
				$title = htmlspecialchars($title);

				$nomargin='';
				if(in_array($ext,$allowed_types))
				{
					$pictures[$key]['url'] 		= '../'.$directory.'/'.$file;
					$pictures[$key]['titre']	= $file;
				}
				$key++;
			}
			closedir($dir_handle);

			if(DEBUG) {
				echo '<pre>';
				print_r($pictures);
				echo '</pre>';
			}
			return $pictures;
		}

		public function showAllMiniature($directory){
			/* MINIATURE */
			$allowed_types=array('jpg','jpeg','gif','png');
			$file_parts=array();
			$ext='';
			$title='';
			$i=0;
			$dir_handle = @opendir($directory) or die("Il y a une erreur avec le dossier d'image");

			$key = 0;

			while ($file = readdir($dir_handle))
			{
				if($file=='.' || $file == '..') continue;

				$file_parts = explode('.',$file);
				$ext = strtolower(array_pop($file_parts));

				$title = implode('.',$file_parts);
				$title = htmlspecialchars($title);

				$nomargin='';
				if(in_array($ext,$allowed_types))
				{
					$mini[$key]['url'] 		= '../'.$directory.'/'.$file;
					$mini[$key]['titre']	= $file;
				}
				$key++;
			}
			closedir($dir_handle);

			return $mini;
		}

	}
?>